// JavaScript Document
function refreshProgress()
{
	//alert('login refreshProgress');
    UploadMonitor.getUploadInfo(updateProgress);
	//alert('end');
}

function updateProgress(uploadInfo)
{
    if (uploadInfo.inProgress)
    {
       $('uploadbutton').disabled = true;
       $('file').disabled = true;
       var fileIndex = uploadInfo.fileIndex;
       var progressPercent = Math.ceil((uploadInfo.bytesRead / uploadInfo.totalSize) * 100);
	   var times=Math.floor((uploadInfo.totalSize-uploadInfo.bytesRead)*uploadInfo.elapsedTime/uploadInfo.bytesRead);
	   var t=getFormateTimes(times);	   
       $('progressBarText').innerHTML = '文件上传进度: ' + progressPercent + '%'+'   剩余时间: '+t+'';
       $('progressBarBoxContent').style.width = parseInt(progressPercent * 3.5) + 'px';
       window.setTimeout('refreshProgress()', 1000);
    }else{
       $('uploadbutton').disabled = true;
       $('file').disabled = true;
	   var fileIndex = uploadInfo.fileIndex;
       var progressPercent = Math.ceil((uploadInfo.bytesRead / uploadInfo.totalSize) * 100);
       $('progressBarText').innerHTML = '文件上传完毕，正在保存中... ';
       $('progressBarBoxContent').style.width = parseInt(progressPercent * 3.5) + 'px';		
    }
    return true;
}
function startProgress()
{		
    $('progressBar').style.display = 'block';
    $('progressBarText').innerHTML = '文件上传进度: 0%';
    $('uploadbutton').disabled = true;
    // wait a little while to make sure the upload has started ..
    window.setTimeout("refreshProgress()", 1000);
    return true;
}
function getFormateTimes(times){
	var t;
	var h=Math.floor(times/3600);
	var m=Math.floor(times/60)%60;
	var s=Math.floor(times%60);
	if(h!=0){
		t=h+' 时'+m+' 分'+s+' 秒';
	}else{
		if(m!=0){
			t=m+' 分'+s+' 秒';
		}else{
			t=s+' 秒';
		}
	}
	return(t);
}

 